package cn.bkw.ytkapi.utils;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.codec.binary.Base64;

import com.alibaba.fastjson.JSONObject;
/**
 * @date 2016-9-01
 * @author wgl
 * @class 常用公共类
 */
public class StringUtil {
	/*
	 * 若obj为空值时，赋予一个默认值defaultvalue
	 */
	public static String StrNoHtml(Object obj, String defaultvalue)
    {
        String str = "";
        try
        {
            str = obj.toString();
        }
        catch(Exception e) { }
        String str2 = "";

        if (new Integer(str.length()).equals(0))
        {
			str2 = defaultvalue;			
        }
        else
        {
            str = str.replace("<", "&lt;");
            str = str.replace(">", "&gt;");
            str = str.replace("\"", "&quot;");
            str = str.replace("'", "&#39;");
            str2 = str;
        }
        return str2;
    }
	public static String StrBackHtml(Object obj, String defaultvalue)
    {
        String str = "";
        try
        {
            str = obj.toString();
        }
        catch(Exception e) { }
        String str2 = "";

        if (new Integer(str.length()).equals(0))
        {
			str2 = defaultvalue;			
        }
        else
        {
            str = str.replace("&lt;", "<");
            str = str.replace("&gt;", ">");
            str = str.replace("&quot;", "\"");
            str = str.replace("&#39;", "'");
            str2 = str;
        }
        return str2;
    }
	public static String StrNoHtmls(Object obj, String defaultvalue)
    {
        String str = "";
        try
        {
            str = obj.toString();
        }
        catch(Exception e) { }
        String str2 = "";

        if (new Integer(str.length()).equals(0))
        {
			str2 = defaultvalue;			
        }
        else
        {
        	str = str.replace(" ", "");
            str2 = str;
        }
        return str2;
    }
	/*
	 * 获取客户端IP
	 */
	public static String getIP(HttpServletRequest request){   
	     String ipAddress = null;   
	     //ipAddress = this.getRequest().getRemoteAddr();   
	     ipAddress = request.getHeader("x-forwarded-for");   
	     if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {   
	      ipAddress = request.getHeader("Proxy-Client-IP");   
	     }   
	     if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {   
	         ipAddress = request.getHeader("WL-Proxy-Client-IP");   
	     }   
	     if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {   
	      ipAddress = request.getRemoteAddr();   
	      if(ipAddress.equals("127.0.0.1")){   
	       //根据网卡取本机配置的IP   
	       InetAddress inet=null;   
	    try {   
	     inet = InetAddress.getLocalHost();   
	    } catch (UnknownHostException e) {   
	     e.printStackTrace();   
	    }   
	    ipAddress= inet.getHostAddress();   
	      }   
	            
	     }   
	  
	     //对于通过多个代理的情况，第一个IP为客户端真实IP,多个IP按照','分割   
	     if(ipAddress!=null && ipAddress.length()>15){ //"***.***.***.***".length() = 15   
	         if(ipAddress.indexOf(",")>0){   
	             ipAddress = ipAddress.substring(0,ipAddress.indexOf(","));   
	         }   
	     }   
	     return ipAddress;
	}
	
	/*
	 * 获取当前时间（数据库格式）
	 */
	public static String getCurrentTime(){		
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式
		return dateFormat.format(now);
	}
	
	/* 
     * 将时间转换为时间戳
     */    
    public static String dateToStamp(String s) throws ParseException{
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime() / 1000;
        res = String.valueOf(ts);
        return res;
    }
	/***
	 *  
	 * 获取指定时间的样式
	 * @param dateString 字符串时间
	 * @param format 时间格式，例如  yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	 
	public static String getDateTimeFormat(String dateString,String format){
		if (!dateString.equals("")) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
			Date date;
			try {
				date = sdf.parse(dateString);
				SimpleDateFormat sdf2= new SimpleDateFormat(format);
				return sdf2.format(date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return "";
			} 
		}
		return "";
	}
	/***
	 *  
	 * 获取指定时间的样式
	 * @param dateString 字符串时间
	 * @param format 时间格式，例如  yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	 
	public static String getDateTimeFormat2(String dateString,String format){
		if (!dateString.equals("")) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");  
			Date date;
			try {
				date = sdf.parse(dateString);
				SimpleDateFormat sdf2= new SimpleDateFormat(format);
				return sdf2.format(date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return "";
			} 
		}
		return "";
	}
	//根据日期取得星期几
	public static String getWeek(String dateString){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		Date date;
		try {
			date = sdf.parse(dateString);
			String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
			if(week_index<0){
			week_index = 0;
			} 
			return weeks[week_index];
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		}
	}
	/***
	 *  
	 * 字符串转date
	 * @return
	 */
	 
	public static Date getDate(String dateString){		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		Date date;
		try {
			date = sdf.parse(dateString);
			return date;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} 
	}
	/***
	 *  
	 * 获取指定时间的样式
	 * @param dateString 字符串时间
	 * @param format 时间格式，例如  yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	 
	public static String getDateTimeFormat1(Date date,String format){		
		SimpleDateFormat sdf2= new SimpleDateFormat(format);
		return sdf2.format(date);
	}
	/*
	 * 获取当前时间（数据库格式）
	 */
	public static String getnumTime(){		
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSS");//可以方便地修改日期格式
		return dateFormat.format(now);
	}
	/*
	 * 获取当前时间（yyyy-MM-dd）
	 */
	public static String getCurrentTime1(){		
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//可以方便地修改日期格式
		return dateFormat.format(now);
	}
	
	public static String UnixTimeToDate(long time){
		Date now = new Date(time*1000); 
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式
		return dateFormat.format(now);
	}
	
	public static Date getdate(int i) // //获取前后日期 i为正数 向后推迟i天，负数时向前提前i天
	{
	 Date dat = null;
	 Calendar cd = Calendar.getInstance();
	 cd.add(Calendar.DATE, i);
	 dat = cd.getTime();
	 SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 Timestamp date = Timestamp.valueOf(dformat.format(dat));
	 return date;
	 }
	public static String getdate1(int i) // //获取前后日期 i为正数 向后推迟i天，负数时向前提前i天
	{
		Date date=new Date();//取时间  
		Calendar calendar = new GregorianCalendar();  
		calendar.setTime(date);  
		calendar.add(calendar.DATE,i);//把日期往后增加一天.整数往后推,负数往前移动  
		date=calendar.getTime(); //这个时间就是日期往后推一天的结果   
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");  
		String dateString = formatter.format(date);  
	 return dateString;
	 }
	public static String getdate2(int i) // //获取前后日期 i为正数 向后推迟i天，负数时向前提前i天
	{
		Date date=new Date();//取时间  
		Calendar calendar = new GregorianCalendar();  
		calendar.setTime(date);  
		calendar.add(calendar.DATE,i);//把日期往后增加一天.整数往后推,负数往前移动  
		date=calendar.getTime(); //这个时间就是日期往后推一天的结果   
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");  
		String dateString = formatter.format(date);  
		return dateString;
	 }
	/**
	 * 获取明天的时间
	 * @return
	 * @throws ParseException
	 */
	public static String gettommorowtime() throws ParseException{
		 Date date = new Date();  
		 SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");  
		  String nowDate = sf.format(date);  
		 Calendar cal = Calendar.getInstance();  
         cal.setTime(sf.parse(nowDate));  
         cal.add(Calendar.DAY_OF_YEAR, +1);  
         String nextDate_1 = sf.format(cal.getTime());  
		return nextDate_1; 
	}
	//获取前5秒的时间
	public static String getbeforetime(int second){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar c = new GregorianCalendar();
		Date date = new Date();
		c.setTime(date);//设置参数时间
		c.add(Calendar.SECOND,-second);//把日期往后增加SECOND 秒.整数往后推,负数往前移动
		date=c.getTime(); //这个时间就是日期往后推一天的结果
		String str = df.format(date);
		return str;
	}
	/*
	 * 获取两个时间的差额
	 */
	public static long getTimeDiff(String start,String end,String unit) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long adiff= 0;
		try
		{
		    Date d1 = df.parse(start);
		    Date d2 = df.parse(end);
		    long diff = d2.getTime() - d1.getTime();
		    if(unit.equals("day")){
		    	adiff = diff / (1000 * 60 * 60 * 24);		    	
		    }else if(unit.equals("hour")){
		    	adiff = diff / (1000 * 60 * 60);		    	
		    }else if(unit.equals("minute")){
		    	adiff = diff / (1000 * 60);		    	
		    }else if(unit.equals("second")){
		    	adiff = diff / 1000;		    	
		    }
		}
		catch (Exception e)
		{
			System.out.println(e.toString());
		}
		return adiff;
	}
	//将秒转为时分秒
	public static String formatSecond(long seconds){
		long hour=seconds/3600;
		long minute=seconds%3600/60;
		long second=seconds%60;
		String times=hour+":"+minute+":"+second;
		return times;
	}

	/***
	 * 将秒转为时分
	 * @param seconds
	 * @return
	 */
	public static String formatSecondtoHourMinute(long seconds){
		long hour=seconds/3600;
		long minute=seconds%3600/60;
		String times=hour+"小时"+minute+"分";
		return times;
	}
	  /** 
     * 获取当前月份的时间范围 
     * @return 
     */  
    public static String getThisMonth(){  
        Calendar startCalendar = Calendar.getInstance();  
        startCalendar.set(Calendar.DAY_OF_MONTH, 1);  
        setMinTime(startCalendar);  
          
        Calendar endCalendar = Calendar.getInstance();  
        endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));  
        setMaxTime(endCalendar);  
    	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
        return formatter.format(startCalendar.getTime())+":"+formatter.format(endCalendar.getTime());  
    }  
    /** 
     * 获取上个月的时间范围 
     * @return 
     */  
    public static String getLastMonth(){  
        Calendar startCalendar = Calendar.getInstance();  
        startCalendar.add(Calendar.MONTH, -1);  
        startCalendar.set(Calendar.DAY_OF_MONTH, 1);  
        setMinTime(startCalendar);  
          
        Calendar endCalendar = Calendar.getInstance();  
        endCalendar.add(Calendar.MONTH, -1);  
        endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));  
        setMaxTime(endCalendar);  
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
        return formatter.format(startCalendar.getTime())+":"+formatter.format(endCalendar.getTime());  
    }  
    /** 
     * 获取当前季度的时间范围 
     * @return current quarter 
     */  
    public static String getThisQuarter() {  
        Calendar startCalendar = Calendar.getInstance();  
        startCalendar.set(Calendar.MONTH, ((int) startCalendar.get(Calendar.MONTH) / 3) * 3);  
        startCalendar.set(Calendar.DAY_OF_MONTH, 1);  
        setMinTime(startCalendar);  
          
        Calendar endCalendar = Calendar.getInstance();  
        endCalendar.set(Calendar.MONTH, ((int) startCalendar.get(Calendar.MONTH) / 3) * 3 + 2);  
        endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));  
        setMaxTime(endCalendar);  
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
        return formatter.format(startCalendar.getTime())+":"+formatter.format(endCalendar.getTime()); 
    }  
    
    /** 
     * 获取上个季度的时间范围 
     * @return 
     */  
    public static String getLastQuarter() {  
        Calendar startCalendar = Calendar.getInstance();  
        startCalendar.set(Calendar.MONTH, ((int) startCalendar.get(Calendar.MONTH) / 3 - 1) * 3);  
        startCalendar.set(Calendar.DAY_OF_MONTH, 1);  
        setMinTime(startCalendar);  
          
        Calendar endCalendar = Calendar.getInstance();  
        endCalendar.set(Calendar.MONTH, ((int) endCalendar.get(Calendar.MONTH) / 3 - 1) * 3 + 2);  
        endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));  
        setMaxTime(endCalendar);  
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
        return formatter.format(startCalendar.getTime())+":"+formatter.format(endCalendar.getTime());
    }  
    private static void setMinTime(Calendar calendar){  
        calendar.set(Calendar.HOUR_OF_DAY, 0);  
        calendar.set(Calendar.MINUTE, 0);  
        calendar.set(Calendar.SECOND, 0);  
        calendar.set(Calendar.MILLISECOND, 0);  
    }  
      
    private static void setMaxTime(Calendar calendar){  
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));  
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));  
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));  
        calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND));  
    }
    
    /**
     * 取得当前时间戳（精确到秒）
     *
     * @return nowTimeStamp
     */
    public static String getNowTimeStamp() {
        long time = System.currentTimeMillis();
        String nowTimeStamp = String.valueOf(time / 1000);
        return nowTimeStamp;
    }
    
    /**
     * 输出图片格式
     * @param str 替换的内容
     * @param screenwidth  屏幕宽度
     * @param screenheight  屏幕高度
     * @return
     */
    public static String GetImage(String str, String screenwidth, String screenheight)
    {
        String result = "",imresult="";
        if (str.length() > 0)
        {
            str = str.replace("点gif", ".gif").replace("［", "[").replace("］", "]");
            result = str;

            result = result.replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"");

            String pattern = "\\<img src=\\u0022(.+?)\\u0022 onload=\\u0022resizeImgSize\\(this\\);\\u0022>";

            String pattern1="\\[([^\\]\\[]+\\.gif)\\]";
            result=result.replaceAll(pattern1,"<img src='http://tu.bkw.cn/urltoimg.aspx?width=" + screenwidth + "&height=" + screenheight + "&url=http://attachment.cnbkw.com/bkwimg/$1'>");
            String pattern2="\\[([^\\]\\[]+\\.jpg)\\]";
            result=result.replaceAll(pattern2,"<img src='http://tu.bkw.cn/urltoimg.aspx?width=" + screenwidth + "&height=" + screenheight + "&url=http://attachment.cnbkw.com/bkwimg/$1'>");
            String pattern3="\\[([^\\]\\[]+\\.png)\\]";
            result=result.replaceAll(pattern3,"<img src='http://tu.bkw.cn/urltoimg.aspx?width=" + screenwidth + "&height=" + screenheight + "&url=http://attachment.cnbkw.com/bkwimg/$1'>");
            String pattern4="\\[([^\\]\\[]+\\.bmp)\\]";
            result=result.replaceAll(pattern4,"<img src='http://tu.bkw.cn/urltoimg.aspx?width=" + screenwidth + "&height=" + screenheight + "&url=http://attachment.cnbkw.com/bkwimg/$1'>");
 
            imresult=result.replace("\r", "").replace("\n", "").replace("\t", "").replace("\\", "\\\\").replace("\"", "\\\"");
        }
        return imresult;
    }
    
	 public static String getimage(String st){
	    	String str="";
	    	if(st.contains("[")&st.contains("]")){
	    		String changestr=change(st.substring(st.indexOf("[")+1,st.indexOf("]")));
	        	str=st.replace(st.substring(st.indexOf("[")+1,st.indexOf("]")), changestr);
	    	}else{
	    		str=st;
	    	}
	        String result = "";
	        if (str.length() > 0){
	            str = str.replace("点gif", ".gif").replace("［", "[").replace("］", "]");
	            result = str;
	            result = result.replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"").replace("＇", "'").replace("&#39;", "'"); ;
	            String pattern = "\\<img src=\\u0022(.+?)\\u0022 onload=\\u0022resizeImgSize\\(this\\);\\u0022>";
	            result=result.replaceAll(pattern,"<img src='http://image.bgycyks.com/$1'>");
	            String pattern1="\\[([^\\]\\[]+\\.gif)\\]";
	            result=result.replaceAll(pattern1,"<img src='http://attachment.cnbkw.com/bkwimg/$1'>");
	            String pattern2="\\[([^\\]\\[]+\\.jpg)\\]";
	            result=result.replaceAll(pattern2,"<img src='http://attachment.cnbkw.com/bkwimg/$1'>");
	            String pattern3="\\[([^\\]\\[]+\\.png)\\]";
	            result=result.replaceAll(pattern3,"<img src='http://attachment.cnbkw.com/bkwimg/$1'>");
	            String pattern4="\\[([^\\]\\[]+\\.bmp)\\]";
	            result=result.replaceAll(pattern4,"<img src='http://attachment.cnbkw.com/bkwimg/$1'>");
	    }
	        String imresult=result.replace("\r", "").replace("\n", "").replace("\t", "");
	        return imresult;
	    }
	 
	 private static String change(String str){
	    	StringBuffer sb = new StringBuffer();  
	    	for(int i=0;i<str.length();i++){
	    	//如果是小写
	    	if(str.substring(i,i+1).equals(str.substring(i,i+1).toLowerCase())){
	    		 sb.append(str.substring(i,i+1));  
	    	}
	    	else{
	    		 sb.append(str.substring(i,i+1).toLowerCase());  
	    	}
	    	}
			return sb.toString();
	    }
    /***
     * 读取阿里云视频地址
     * @param voidpath
     * @param workflowname
     * @param definition
     * @return
     */
    public static String getAlyVideoUrl(String videoCode, String workflowname, String definition)
    {
        if (!"".equals(videoCode))
        {
        	String url = "",ossurl="";
        	/*try {
        		ossurl = URLEncoder.encode(voidpath.replace("+", "%2B").replace(" ", "%2B"),"utf-8");
			} catch (UnsupportedEncodingException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
        	String postresult = HttpClientUtil.sendHttpPost("http://vodaly.bkw.cn:8080/getvoideurl", "voidepath=" + ossurl + "&workflowname=" + workflowname);*/
			String postresult = HttpClientUtil.sendHttpPost("http://alymts.cnbkw.com:8080/video/getvideoinfo", "videocode=" + videoCode);
        	//System.out.println(postresult);
            try
            {
                JSONObject jo = JSONObject.parseObject(postresult);
                /*
                 {
                    "errcode":"0",
                    "ossurl":"http://bkw-video-out.oss-cn-hangzhou.aliyuncs.com/Act-ss-mp4-ld/9415b0fa0a334e7296841c747d4069f1/2016-工程类-一级建造师执业资格考试-机电工程管理与实务-003-006.mp4",
                    "cndurl":"http://alyvideo.cnbkw.com/Act-ss-mp4-ld/9415b0fa0a334e7296841c747d4069f1/2016-工程类-一级建造师执业资格考试-机电工程管理与实务-003-006.mp4"
                }
                 */
                if (jo.getString("errcode").equals("0"))
                {
                	//System.out.print("123");
                    url = jo.getString("cndurl").replace("Act-ss-mp4-hd", "Act-ss-mp4-sd").replace("Act-ss-mp4-ld", "Act-ss-mp4-sd");
                    if (definition.equals("ld"))
                    {
                        url = url.replace("Act-ss-mp4-sd", "Act-ss-mp4-ld");
                    }
                    else if (definition.equals("hd"))
                    {
                        url = url.replace("Act-ss-mp4-sd", "Act-ss-mp4-hd");
                    }
                }
            }
            catch(Exception e)
            {
            	System.out.print(e);
            }
            //Log.WriteLog(url);
            return url;

        }
        else
        {
            return "";
        }
    }
    
    public static String getBanxingName(String banxing)
    {
    	if(banxing.equals("1")){
    		return "标准班";
    	}else if(banxing.equals("2")){
    		return "VIP班";
    	}else if(banxing.equals("4")){
    		return "刷题班";
    	}else if(banxing.equals("6")){
    		return "无忧班";
    	}else if(banxing.equals("3")){
    		return "尊享班";
    	}else if(banxing.equals("5")){
    		return "考前串讲班";
    	}else if(banxing.equals("7")){
    		return "直播课程";
    	}else if(banxing.equals("8")){
    		return "考点精讲班";
    	}else{
    		return "暂无";
    	}
    }
    
    public static String getBigclassid(String bigclass)
    {
    	if(bigclass.equals("金融类")){
    		return "1";
    	}else if(bigclass.equals("财会类")){
    		return "2";
    	}else if(bigclass.equals("工程类")){
    		return "4";
    	}else if(bigclass.equals("医药类")){
    		return "7";
    	}else if(bigclass.equals("其他类")){
    		return "6";
    	}else if(bigclass.equals("学历类")){
    		return "10";
    	}else if(bigclass.equals("职业素养类")){
    		return "9";
    	}else{
    		return "0";
    	}
    }  
    
    
    public static String lastday(){
    	//显示最近N天
    	Calendar cal = Calendar.getInstance();
	    for(int i = 0 ; i < 27 ; i++){
		    /*获取当前日历的日期的星期数（1:星期天）*/
		    int week_index = cal.get(Calendar.DAY_OF_WEEK);  
		    Date date=cal.getTime(); 
		    /*日期格式化 yyyy-MM-dd M必须大写*/
		    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
		    String dateString = formatter.format(date);
		    System.out.println(week_index+","+dateString);

		    cal.add(cal.DATE,-1);
		}
    	return "";
    }
    
    /***
     * 去掉数组重复值
     * @param array
     * @return
     */
    public static String[] quchong(String[] arr) {
		//使用List集合
		List ls = new ArrayList();
		for(int i=0;i<arr.length;i++) {
			if(!ls.contains(arr[i])) {
				ls.add(arr[i]);
			}
		}

		String[] newArr = new String[ls.size()];
		for(int i=0;i<ls.size();i++) {
			newArr[i] = ls.get(i).toString();
		}
		return newArr;	
	}
    
    //找出两数组不同的元素
    public static <T> List<T> compare(T[] t1, T[] t2) {    
        List<T> list1 = Arrays.asList(t1);    
        List<T> list2 = new ArrayList<T>();    
        for (T t : t2) {    
            if (!list1.contains(t)) {    
                list2.add(t);    
            }    
        }    
        return list2;    
    }   
    
    /***
     * BASE65 编码
     * @param abc
     * @return
     */
    public static String Base64Encode(String abc){   
    	String encodedText = "";
		try {
			Base64 base64 = new Base64();
	    	byte[] textByte;
			textByte = abc.getBytes("UTF-8");
			//编码
	    	encodedText = base64.encodeToString(textByte);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return encodedText;
    }
    

    /***
     * BASE65 解码
     * @param abc
     * @return
     */
    public static String Base64Decode(String abc){   
    	String decodedText = "";
		try {
			Base64 base64 = new Base64();
			decodedText = new String(base64.decode(abc), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return decodedText;
    }
    /***
     * 检查字符串带有数字或这英文的长度
     * @param conent
     * @return
     */
    public static int CheckNumberSize(String content){
    	String regEx="[a-zA-Z0-9]";//提取聊天当中的数字和英文
		Pattern p=Pattern.compile(regEx);
		Matcher m=p.matcher(content);
		StringBuffer sb = new StringBuffer();
		while(m.find()){
			sb.append(m.group());
		}
    	return sb.length();
    }
    
    public static String divide_percent(String fenzi,String fenmu){
    	double d_fenzi = Double.valueOf(fenzi.toString());
    	double d_fenmu = Double.valueOf(fenmu.toString());
    	if(d_fenmu==0){
    		return "0";
    	}else{
	    	DecimalFormat df =new DecimalFormat();
	    	df.setMaximumFractionDigits(2);
	    	df.setMinimumFractionDigits(2);
	    	String orderRate = df.format(d_fenzi *100.00 / d_fenmu) ;
	    	return orderRate;
    	}
    }
    /***
     * 检查字符串带有中文数字的长度
     * @param conent
     * @return
     */
    public static int CheckChineseNumberSize(String content){
    	String regEx="[壹贰叁肆伍陆柒捌玖拾一二三四五六七八九零]";//提取聊天当中的中文数字
		Pattern p=Pattern.compile(regEx);
		Matcher m=p.matcher(content);
		StringBuffer sb = new StringBuffer();
		while(m.find()){
			sb.append(m.group());
		}
    	return sb.length();
    }
    /***
     * 加星号隐藏手机号码
     * @param xinghao 1：加星号 0：不加
     * @param str
     * @return
     */
	public static String jiaxinghao(String xinghao,String str){
		int len = str.length();
		if(xinghao.equals("0")){
			return str;
		}else{
			if(len==0){
				return "***";
			}else{
		        if (len <= 3)
		        {
		            str = str.substring(0, 1) + "**";
		        }
		        else if (len <= 5)
		        {
		            str = str.substring(0, len - 3) + "**" + str.substring(len - 1);
		        }
		        else if (len == 6)
		        {
		            str = str.substring(0, 2) + "**" + str.substring(len - 2);
		        }
		        else if (len > 6)
		        {
		            str = str.substring(0, 3) + "**" + str.substring(len - 4);
		        }
		        return str;		
			}
		}
	}

	public static String getTimeFomatNew(String time,String fomatOld,String fomatNew) throws Exception {
		SimpleDateFormat sfd = new SimpleDateFormat(fomatOld);
		Date d1 = sfd.parse(time);
		SimpleDateFormat sfd2 = new SimpleDateFormat(fomatNew);
		return sfd2.format(d1);
	}

	public static String formatSecond3(String seconds1) {
		Long seconds = Long.parseLong(seconds1);
		long hour = seconds / 3600;
		long minute = seconds % 3600 / 60;
		long second = seconds % 60;
		String times = hour + "时" + minute + "分" + second + "秒";
		return times;

	}
	public static String getTimeFormat(Date time,String formatKey) {

		DateFormat format = new SimpleDateFormat(formatKey);
		return format.format(time);
	}
	
	/***
	 *  
	 * 获取指定时间加减天小时月。。
	 * @param time date时间
	 * @param type 加减类型
	 * @return num 加减数量
	 */
	public static Date getCalendarAdd(Date time,String type,int num) {
		Calendar calendar = Calendar.getInstance();  
		calendar.setTime(time);  
		if (type.equals("hour")) {
			calendar.add(Calendar.HOUR, num);//当前时间减去num小时
		}else if (type.equals("minute")) {
			calendar.add(Calendar.MINUTE, num);//当前时间减去num分钟
		}else if (type.equals("second")) {
			calendar.add(Calendar.SECOND, num);//当前时间减去num秒
		}else if (type.equals("year")) {
			calendar.add(Calendar.YEAR, num);//当前时间减去num年
		}else if (type.equals("month")) {
			calendar.add(Calendar.MONTH, num);//当前时间减去num月
		}else if (type.equals("day")) {
			calendar.add(Calendar.DATE, num);//当前时间减去num天
		}
		return calendar.getTime();
	}
	/***
	 *  
	 * 获取现在的时间 到晚上12点相差几分钟
	 * @param time date时间
	 * @param type 加减类型
	 * @return num 加减数量
	 */
	public static int getNowToTommorrMinute() {
		Calendar calendar = Calendar.getInstance();  
		Date now_date=new Date();
		calendar.setTime(now_date); 
		calendar.add(Calendar.DATE, 1);//当前时间加1天
		calendar.set(Calendar.HOUR, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		int minute=(int) ((calendar.getTime().getTime()-now_date.getTime())/1000/60);
		return minute;
	}
	public static boolean CheckMobile(String mobile)
    {
        if (mobile==null||mobile.equals(""))
        {
            return false;
        }
        else
        {
            String re = "^[1][3,4,5,6,8,7,9][0-9]{9}$";
            if (mobile.matches(re)) {
            	return true; 
            } else {
            	return false; 
            }

        }
    }
	//发送短信
    public static String sendsms(String para)
    {
        return HttpClientUtil.sendHttpPost("http://sendmail.bkw.cn/App/alysms_sendsms.ashx", para);
    }
  //发送给客户邮件
    public static String sendcurstomermail(String para)
    {
        return HttpClientUtil.sendHttpPost("http://sendmail.bkw.cn/App/sendbyalymail.ashx", para);
    }
    //过滤特殊字符
    public static String Guolv(String result)
    {
    	if (result==null||result.equals("")) {
			return "";
		}else {
			 return result.replaceAll("\\r", "").replaceAll("\\n", "").replaceAll("&nbsp;", " ").replaceAll("\\t", "").replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\"");
		}
       
    }
    //验证字符串不为“”并且不为null
    public static boolean checkStringNotNULL(String result)
    {
    	if (result!=null&&!result.equals("")) {
			return true;
		}else {
			return false;
		}
    }
    //发送邮件
    public static void SendNotifyMail(String salermail,String strTitle,String strContent)
    {
    	HttpClientUtil.sendHttpPost("http://sendmail.bkw.cn/App/sendbyqqmail.ashx", "tomail=" + salermail + "&title=" + strTitle + "&body=" + strContent.replaceAll("&", "%26") + "&rank=2");
    }
    //将时间转换成小时的形式
    public static int getHour(String val) {
        int a = 0;
        if (Integer.parseInt(val) >= 3600)
        {
            a = Integer.parseInt(val) / 3600;
        }
        else {
            a = Integer.parseInt(val);
        }
        return a;
    }
    /***
	 * 输出接口请求参数
	 * @param request
	 * @return
	 */
	public static String WriteRequestParameter(HttpServletRequest request){
		Enumeration<String> names = request.getParameterNames(); 
	    StringBuilder output = new StringBuilder(); 
	    while (names.hasMoreElements()) { 
	      String name = (String) names.nextElement(); 
	      output.append(name).append("="); 
	      String values[] = request.getParameterValues(name); 
	      for (int i = 0; i < values.length; i++) { 	        
	        output.append(values[i]); 
	      } 
	      if (names.hasMoreElements()) 
	        output.append("&"); 
	    }
	    return output.toString();
	}
    
}
